﻿using IceCS.Moq.FootballManager.Core.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IceCS.Moq.FootballManager.Core
{
    /// <summary>
    /// 转会审批服务
    /// </summary>
    public class TransferApprovalService
    {
        /// <summary>
        /// 剩余预算
        /// </summary>
        private const decimal RemainingTotalBudget = 3000000;

        private IPhysicalExamination _physicalExamination;
        public TransferApprovalService(IPhysicalExamination physicalExamination)
        {
            _physicalExamination = physicalExamination;
        }

        /// <summary>
        /// 计算转会审批
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public TransferResult Evaluate(FootballPlayer player)
        {
            var isHealthy = _physicalExamination.IsHealthy(player.PlayerAge, player.PlayerStrength, player.PlayerSpeed);
            if (!isHealthy)
            {
                return TransferResult.Rejected;
            }
            var totalTransferFee = player.TransferFee + player.ContractYears * player.AnnualSalary;
            if (RemainingTotalBudget < totalTransferFee)
            {
                return TransferResult.Rejected;
            }
            if (player.PlayerAge < 30)
            {
                return TransferResult.Approved;
            }
            if (player.IsSuperStar)
            {
                return TransferResult.ReferredToBoss;
            }
            return TransferResult.Rejected;
        }
    }
}
